package com.ocom.payconfig.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.card.EntityXfAccountInfo;
import com.ocom.common.vo.ccb.GetCcbAccountListRVo;
import com.ocom.payconfig.vo.GetListRechargeRVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoCcbAccount extends BaseMapper<EntityXfAccountInfo> {

    @Select({"<script>",
            "select p.p_id , p.com_id , p.p_code , p.dept_id, p.p_name , a.account_no , a.account_name , a.id AS accountId, " +
                    "a.acc_type_id , at.acc_type_name, c.card_no , c.end_date AS endTime, d.dept_name , c.card_state , sn.sign_no , sn.status AS signStatus" +
                    " from personnel_info p " +
                    "left join xf_sign_no sn  on sn.com_id=p.com_id and sn.p_id=p.p_id  and sn.merch_id=0 and sn.pay_way=32 "+
                    "LEFT JOIN card_info c ON p.com_id=c.com_id AND p.p_id=c.p_id AND card_state IN (0,1)"+
                    "LEFT JOIN dept_info d ON p.com_id=d.com_id AND p.dept_id=d.dept_id " +
                    "INNER JOIN xf_account_info a ON p.com_id=a.com_id AND p.p_id=a.p_id " +
                    "INNER JOIN xf_account_type at ON p.com_id=at.com_id AND a.acc_type_id=at.acc_type_id " +
                    "where p.status=0 and a.account_state=0 and p.com_id=#{comId} "+
//                    " <when test=\"deptIdsList!=null and deptIdsList.size() &gt; 0 \" > "+
//                    " AND (p.dept_id is null or p.dept_id  in " +
//                    " <foreach collection='deptIdsList' item='id' open='(' separator=',' close='))'> "+
//                    " #{id} "+
//                    " </foreach> "+
//                    "</when>"+
                    " <when test=\"deptIds!=null and deptIds!=0\"> "+
                    " AND p.dept_id =  #{deptIds} "+
                    " </when> "+
                    " <when test=\"pId!=null and pId!=0\"> "+
                    " AND p.p_id =  #{pId} "+
                    " </when> "+
                    " <when test=\"pName!=null and pName!=''\"> "+
                    " AND p.p_name like concat('%', #{pName}, '%') "+
                    " </when> "+
                    " <when test=\"pCode!=null and pCode!=''\" > "+
                    " AND p.p_code  like concat('%', #{pCode}, '%') "+
                    " </when> "+
                    " <when test=\"cardNo!=null and cardNo!=''\" > "+
                    " AND c.card_no  like concat('%', #{cardNo}, '%') "+
                    " </when> "+
                    " <when test=\"accountNo!=null and accountNo!=''\" > "+
                    " AND a.account_no  like concat('%', #{accountNo}, '%') "+
                    " </when> "+
                    " <when test=\"accTypeId!=null and accTypeId!=''\" > "+
                    " AND a.acc_type_id=#{accTypeId} "+
                    " </when> "+
                    " group by  p.com_id,p.p_id "+
                    "order by p.update_time desc"+
            "</script>"})
    List<GetCcbAccountListRVo> getCcbAccountList(Long comId, Integer deptIds, String pCode,
                                                 String pName, String cardNo, String accountNo, Long accTypeId, Long pId);

}
